import beans.dao.Student;
import beans.dao.UserDO;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

//实例化
public class SpringNewClass {

    //构造方法
    @Test
    public void test1()
    {
        //1.创建一个spring容器
        ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("newclass.xml");
        //2.从spring容器中获取对象
        UserDO userDO = (UserDO) applicationContext.getBean("user", UserDO.class);
        userDO.insert();
    }
    //简单工厂模式方法（实际上就是在工厂内new一个）
    @Test
    public void test2()
    {
        ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext("newclass.xml");
        UserDO user1 = classPathXmlApplicationContext.getBean("user1", UserDO.class);
        user1.insert();
    }
    //工厂方法模式方法
    @Test
    public void test3()
    {
        ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext("newclass.xml");
        UserDO user2 = classPathXmlApplicationContext.getBean("user2", UserDO.class);
        user2.insert();
    }
    //实现FactoryBean接口
    @Test
    public void test4()
    {
        ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext("newclass.xml");
        UserDO user3 = classPathXmlApplicationContext.getBean("user3", UserDO.class);
        user3.insert();
    }


    @Test
    public void test5()
    {
        ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext("newclass.xml");
        Student studentBean = classPathXmlApplicationContext.getBean("StudentBean", Student.class);
        studentBean.Brith();
    }
}
